package com.mywork.activity;

import android.content.Intent;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.ciko.code.base.BaseActicity;
import com.ciko.code.utils.Util;
import com.mywork.R;

/**
 * Created on 2016/3/31.
 */
public class ResRemarkActivity extends BaseActicity implements BaseActicity.OnNavRightClickListener {
    private String mTitle;
    private String content;
    private String type;
    private boolean isVisi = false;
    private EditText remarkEt;
    private TextView remarkTv;

    @Override
    protected void getIntenData() {
        super.getIntenData();
        mTitle = getIntent().getStringExtra("title");
        content = getIntent().getStringExtra("content");
        type = getIntent().getStringExtra("type");
        if (!TextUtils.isEmpty(type)) {
            isVisi = true;
            switch (type) {
                case "1":
                    mTitle = "出差";
                    break;
                case "2":
                    mTitle = "请假";
                    break;
                case "3":
                    mTitle = "其他";
                    break;
            }
        }
    }

    @Override
    protected void initTopBar() {
        setTitle(mTitle);
        enableNavLeftImg();
        if (!isVisi) {
            enableNavRightIv("完成");
        }
    }

    @Override
    protected void initLayout() {
        setContentView(R.layout.activity_res_remark);
    }

    @Override
    protected void initView() {
        remarkEt = (EditText) findViewById(R.id.remark_res_et);
        remarkTv = (TextView) findViewById(R.id.remark_res_tv);
        if (!isVisi) {
            remarkEt.setVisibility(View.VISIBLE);
            remarkTv.setVisibility(View.GONE);
            remarkEt.setHint("请输入" + mTitle + "理由...");
        } else {
            remarkEt.setVisibility(View.GONE);
            remarkTv.setVisibility(View.VISIBLE);
            remarkTv.setText(content);
        }
    }

    @Override
    protected void initAdapter() {

    }

    @Override
    protected void initDates() {

    }

    @Override
    protected void initListener() {
        setOnNavRightClickListener(this);
    }

    @Override
    public void onNavRightClick() {
        if (!isVisi) {
            String remarks = remarkEt.getText().toString().trim();
            if (TextUtils.isEmpty(remarks)) {
                Util.showToast(this, "请输入" + mTitle);
            } else if (remarks.length() > 50) {
                Util.showToast(this, "字数不能超过50");
            } else {
                Intent intent = new Intent();
                intent.putExtra("content", remarks);
                if (TextUtils.equals(mTitle, "出差")) {
                    setResult(1000, intent);
                } else if (TextUtils.equals(mTitle, "请假")) {
                    setResult(1001, intent);
                } else if (TextUtils.equals(mTitle, "备注原因")) {
                    setResult(1002, intent);
                }
                finish();
            }
        } else {
            finish();
        }
    }
}
